namespace SB2.Core;
/// <summary>
/// 角色
/// </summary>

public class RoleAppService : ICoreService
{
    public RoleAppService()
    {
    }

    /// <summary>
    /// 全部权限
    /// </summary>
    /// <returns></returns>
    public object GetTreeAll()
    {
        var data = PermissionCode.GetCodes();
        var res = data
        .Where(m => m.Value != null)
        .Select(m => new TreeResponse<string>
        {
            label = m.Value.Name,
            key = m.Key,
            tdata = m.Value.ParentPermission
        }).ToList();

        foreach (var item in res)
        {
            item.children = res.Where(m => m.tdata == item.key).ToList();
            if (!item.children.Any()) item.children = null;
        }

        return res.Where(m => m.tdata == null).ToList();
    }

}